package com.example.langchain4j;

import com.example.langchain4j.service.DifyChangeService;
import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.community.model.dashscope.QwenStreamingChatModel;
import dev.langchain4j.model.input.Prompt;
import dev.langchain4j.model.input.PromptTemplate;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;

@SpringBootTest
public class QwenChatText {

    @Resource
    DifyChangeService  difyChangeService;

    @Test
    public void test() {
        String msg = """
                你好{{abc1}}撒地方{{abc2}}
                """;
        HashMap<String, Object> map = new HashMap<>();
        map.put("abc1","张三");
//        map.put("abc2","李四");
        PromptTemplate from = PromptTemplate.from("你好 " +
                "{{abc1}} " +
                "撒地方");
        String template = from.template();
        System.out.println(template);
        Prompt prompt = from.apply(map);
        System.out.println(prompt.text());
//        PromptTemplate promptTemplate = PromptTemplate.from(
//                """
//                        尽你所能回答以下问题:
//
//                        问题:
//                        {{question}}
//
//                        请根据以下信息作答:
//                        {{information}}""");
//        Map<String, Object> variables = new HashMap<>();
//        variables.put("question", "这是问题");
//        variables.put("information", "这是信息");
//        Prompt prompt = promptTemplate.apply(variables);
//
//        System.out.println("prompt: "+prompt.text());
    }

    @Resource
    QwenStreamingChatModel  qwenStreamingChatModel;

    @Resource
    QwenChatModel  qwenChatModel;
    @Test
    public void test2() {
//        HashMap<String, Object> hashMap = new HashMap<>();
//        hashMap.put("enable_thinking",false);
//        QwenChatRequestParameters build = QwenChatRequestParameters.builder().custom(hashMap).build();
//        QwenChatModel qwenChatModel1 = QwenChatModel.builder()
//                .apiKey("sk-53dfc5436d04469184ab55011d1bb1fc")
//                .modelName("qwen3-14b")
//                .defaultRequestParameters(build).build();
//        String response = qwenChatModel1.chat("你好");
//        System.out.println(response);
//        qwenStreamingChatModel.chat("你好",new StreamingChatResponseHandler(){
//
//            @Override
//            public void onPartialResponse(String s) {
//                System.out.println(s);
//            }
//
//            @Override
//            public void onCompleteResponse(ChatResponse chatResponse) {
//                System.out.println(chatResponse);
//            }
//
//            @Override
//            public void onError(Throwable throwable) {
//                throwable.printStackTrace();
//            }
//        });

    }
}
